import sys
import logging
import argparse

from receipt_identify.gui import gui_run
from receipt_identify import VERSION

# 添加 logger
logger = logging.getLogger(__name__)


def _prase_args():
    parser = argparse.ArgumentParser(exit_on_error=False)
    parser.add_argument(
        "-d",
        "--debug",
        action="store_true",
        help="show debug information",
    )
    args = parser.parse_args()

    return args


def _init_logging(args):
    if args.debug:
        log_level = logging.DEBUG
        log_handler = [
            logging.StreamHandler(stream=sys.stdout),
            logging.FileHandler("app.log"),
        ]
    else:
        log_level = logging.INFO
        log_handler = [
            logging.StreamHandler(stream=sys.stdout),
        ]

    logging.basicConfig(
        level=log_level,
        format="[%(asctime)s] %(levelname)s: %(message)s",
        handlers=log_handler,
    )


def main(args):
    gui_run()


if __name__ == "__main__":
    args = _prase_args()
    _init_logging(args)
    main(args)
